﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class PRODUCT_GROUP
    {
        private bool m_Active;
        private string m_Description;
        private string m_ProductGroup_ID;
        private string m_ProductGroup_Name;

        public PRODUCT_GROUP()
        {
            this.m_ProductGroup_ID = "";
            this.m_ProductGroup_Name = "";
            this.m_Description = "";
            this.m_Active = true;
        }

        public PRODUCT_GROUP(string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            this.m_ProductGroup_ID = ProductGroup_ID;
            this.m_ProductGroup_Name = ProductGroup_Name;
            this.m_Description = Description;
            this.m_Active = Active;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "ProductGroup_Name", "ProductGroup_ID");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["ProductGroup_ID"] = "All";
            row["ProductGroup_Name"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "ProductGroup_Name", "ProductGroup_ID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { this.m_ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public string Delete(string ProductGroup_ID)
        {
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string ProductGroup_ID)
        {
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string ProductGroup_ID)
        {
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_GROUP_Delete", myParams, myValues);
        }

        public bool Exist(string ProductGroup_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
            }
            return hasRows;
        }

        public bool Exist(SqlTransaction myTransaction, string ProductGroup_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader.Dispose();
            }
            return hasRows;
        }

        public bool ExistByName(string ProductGroup_Name)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ProductGroup_Name" };
            object[] myValues = new object[] { ProductGroup_Name };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GROUP_GetByName", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader.Dispose();
            }
            helper.Close();
            return hasRows;
        }

        public bool ExistByName(SqlTransaction myTransaction, string ProductGroup_Name)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ProductGroup_Name" };
            object[] myValues = new object[] { ProductGroup_Name };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "PRODUCT_GROUP_GetByName", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader.Dispose();
            }
            return hasRows;
        }

        public string Get(string ProductGroup_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductGroup_ID = Convert.ToString(reader["ProductGroup_ID"]);
                    this.m_ProductGroup_Name = Convert.ToString(reader["ProductGroup_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string ProductGroup_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductGroup_ID = Convert.ToString(reader["ProductGroup_ID"]);
                    this.m_ProductGroup_Name = Convert.ToString(reader["ProductGroup_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string ProductGroup_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductGroup_ID" };
            object[] myValues = new object[] { ProductGroup_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "PRODUCT_GROUP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductGroup_ID = Convert.ToString(reader["ProductGroup_ID"]);
                    this.m_ProductGroup_Name = Convert.ToString(reader["ProductGroup_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string GetByName(string ProductGroup_Name)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductGroup_Name" };
            object[] myValues = new object[] { ProductGroup_Name };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GROUP_GetByName", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductGroup_ID = Convert.ToString(reader["ProductGroup_ID"]);
                    this.m_ProductGroup_Name = Convert.ToString(reader["ProductGroup_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                reader.Dispose();
            }
            helper.Close();
            return str;
        }

        public string GetByName(SqlTransaction myTransaction, string ProductGroup_Name)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductGroup_Name" };
            object[] myValues = new object[] { ProductGroup_Name };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "PRODUCT_GROUP_GetByName", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductGroup_ID = Convert.ToString(reader["ProductGroup_ID"]);
                    this.m_ProductGroup_Name = Convert.ToString(reader["ProductGroup_Name"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                reader.Dispose();
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_GROUP_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_ProductGroup_ID, this.m_ProductGroup_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_ProductGroup_ID, this.m_ProductGroup_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { ProductGroup_ID, ProductGroup_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { ProductGroup_ID, ProductGroup_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            this.m_ProductGroup_ID = ProductGroup_ID;
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { ProductGroup_ID, ProductGroup_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_GROUP_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("PRODUCT_GROUP", "ProductGroup_ID", "NH");
        }

        public string NewID(SqlTransaction myTransaction)
        {
            return SqlHelper.GenCode(myTransaction, "PRODUCT_GROUP", "ProductGroup_ID", "NH");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_ProductGroup_ID, this.m_ProductGroup_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { this.m_ProductGroup_ID, this.m_ProductGroup_Name, this.m_Description, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { ProductGroup_ID, ProductGroup_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { ProductGroup_ID, ProductGroup_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_GROUP_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string ProductGroup_ID, string ProductGroup_Name, string Description, bool Active)
        {
            string[] myParams = new string[] { "@ProductGroup_ID", "@ProductGroup_Name", "@Description", "@Active" };
            object[] myValues = new object[] { ProductGroup_ID, ProductGroup_Name, Description, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_GROUP_Update", myParams, myValues);
        }

        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public string ProductGroup_ID
        {
            get
            {
                return this.m_ProductGroup_ID;
            }
            set
            {
                this.m_ProductGroup_ID = value;
            }
        }

        public string ProductGroup_Name
        {
            get
            {
                return this.m_ProductGroup_Name;
            }
            set
            {
                this.m_ProductGroup_Name = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class PRODUCT_GROUP";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }
    }
}

